package com.lrs.java.j2se_self.collection;

import java.util.*;
public class InteratorEx {
	public static void main(String[] args){
		Collection c = new ArrayList();
		c.add(new Integer(100));
		c.add("HelloWorld!");
		c.add(new Name("L1","z1"));
		c.remove(new Integer(100));
		c.remove("HelloWorld!");
		//c.remove(new Name("L1","z1"));
		//System.out.println(c);
		
		Collection c2 = new HashSet();
		c2.add(new Name("ffsfas","xcjsl"));
		c2.add(new Name("dfasfa","fdjal"));
		c2.add(new Name("f2","z2"));
		for(Iterator i=c2.iterator();i.hasNext();){
			Name n = (Name)i.next();
			/*if(n.getFirstN().length()<3){
				i.remove();
			}*/
			System.out.println(n.getFirstN() + "");
		}
		//System.out.println(c2);
	}
}

class Name implements Comparable {
	private String firstN;
	private String lastN;
	
	public Name(String firstName,String lastName){
		this.firstN = firstName;
		this.lastN = lastName;
	}
	
	public String getFirstN(){
		return firstN;
	}
	public String getLastN(){
		return lastN;
	}
	public String toString(){
		return firstN + "," + lastN;
	}
	public int compareTo(Object o){
		Name n = (Name)o;
		int lastCmp = 
            lastN.compareTo(n.lastN);
        return 
             (lastCmp!=0 ? lastCmp :
              firstN.compareTo(n.firstN));
	}
}